var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/help/StaticDicHelp.tsx
var StaticDicHelp_exports = {};
__export(StaticDicHelp_exports, {
  MultipleStaticDicHelpSelect: () => MultipleStaticDicHelpSelect,
  StaticDicHelp: () => StaticDicHelp,
  StaticDicHelpSelect: () => StaticDicHelpSelect
});
module.exports = __toCommonJS(StaticDicHelp_exports);
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_common = require("./common");
var { Option } = import_functionalComponent.Tabs;
var { Header, Footer, MultipleButtons } = import_functionalComponent.BaseHelp;
var tableProps = {
  cache: false,
  headerMenu: false,
  style: { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 }
};
function addDisabledProperty(data) {
  return data.map((item) => {
    if (item.children.length !== 0) {
      item.children = addDisabledProperty(item.children);
      return { ...item, disabled: true };
    } else {
      return item;
    }
  });
}
function HelpContent() {
  const {
    request,
    ok,
    contentParams: { getFieldValue, columns, helpTitle, typeCode, selectedArray, multiple, selectLeafOnly, footer },
    locale,
    randomKey
  } = (0, import_react.useContext)(import_functionalComponent.HelpContext);
  const btnRef = (0, import_react.useRef)();
  const [activeKey, setActiveKey] = (0, import_react.useState)("0");
  const rightTable = (0, import_react.useRef)();
  const getTable = () => import_util.iup.compIns[`${typeCode}_${randomKey}_${activeKey}`].getApi();
  const getResult = () => {
    if (multiple) {
      const result = rightTable.current.getApi().getRows().map((r) => ({
        value: getFieldValue(r),
        label: getFieldValue(r, "label"),
        origin: { ...r }
      }));
      return result.length > 0 ? result : void 0;
    } else {
      const value = getTable().getSelectedData()[0];
      if (value) {
        return { value: getFieldValue(value), label: getFieldValue(value, "label"), origin: { ...value } };
      }
      return void 0;
    }
  };
  const toRight = (values) => {
    if (multiple) {
      btnRef.current.toRight(values);
    } else {
      ok(getResult());
    }
  };
  const onSearch = (value) => {
    if (activeKey === "0") {
      getTable().query({ keyword: value });
    } else {
      getTable().filter(value);
    }
  };
  const tabTitle = (t) => /* @__PURE__ */ import_react.default.createElement("span", { style: { padding: "0 8px" } }, t);
  const tabBarExtraContent = /* @__PURE__ */ import_react.default.createElement(import_baseComponent.Search, { size: "small", allowClear: true, placeholder: locale.searchPlaceholder, onSearch });
  if (multiple) {
    tableProps.rowSelection = {
      type: [import_functionalComponent.TableSelectionModel.CHECKBOX],
      autoCheckedChildren: false
    };
    tableProps.rowChecked = true;
    tableProps.rowSelected = false;
  } else {
    tableProps.rowSelection = void 0;
    tableProps.rowChecked = false;
    tableProps.rowSelected = true;
  }
  if (selectLeafOnly) {
    tableProps.rowSelection = {
      ...tableProps.rowSelection,
      disabled: (row) => {
        var _a;
        return (_a = row.children) == null ? void 0 : _a.length;
      }
    };
  }
  const setMultiTableData = (rows) => {
    const selected = [];
    const existValues = rightTable.current.getApi().getRows().map((r) => getFieldValue(r));
    rows.forEach((row, index) => {
      var _a;
      if (existValues.indexOf(getFieldValue(row)) === -1) {
        const newVal = JSON.parse(JSON.stringify(row));
        delete newVal.checked;
        if (!selectLeafOnly || !((_a = newVal == null ? void 0 : newVal.children) == null ? void 0 : _a.length)) {
          selected.push(newVal);
        }
      }
    });
    rightTable.current.getApi().addRows(selected);
  };
  const renderTable = (index) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        ...tableProps,
        isTree: true,
        defaultExpand: "all",
        style: { ...tableProps.style, borderTopWidth: 0 },
        id: `${typeCode}_${randomKey}_${index}`,
        columns,
        onRow: (rowIndex, table) => ({
          onDoubleClick: () => toRight([table.getRow(rowIndex)])
        }),
        request
      }
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, null, /* @__PURE__ */ import_react.default.createElement(Header, { title: helpTitle || "静态数据" }), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { direction: "row", style: { padding: "0 5px 5px 5px", borderBottom: 0 } }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { flex: 2 }, /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Tabs, { className: "fit-height", size: "small", onChange: setActiveKey, tabBarExtraContent }, /* @__PURE__ */ import_react.default.createElement(Option, { tab: tabTitle(locale.List), key: "0" }, /* @__PURE__ */ import_react.default.createElement("div", { style: { height: "100%" } }, renderTable(0))))), multiple && /* @__PURE__ */ import_react.default.createElement(
    MultipleButtons,
    {
      addResult: (values) => setMultiTableData(values),
      getRowKey: getFieldValue,
      outRef: btnRef,
      getActiveTable: getTable,
      getResultTable: () => rightTable.current.getApi()
    }
  ), multiple && /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { style: { paddingTop: 7 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      columns,
      dataSource: selectedArray,
      ref: rightTable,
      onRow: (rowIndex) => ({
        onDoubleClick: () => btnRef.current.toLeft(rowIndex)
      })
    }
  ))), /* @__PURE__ */ import_react.default.createElement(Footer, { getResult }, footer && /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: 1, width: 0 }, children: footer })));
}
var StaticDicHelp = (0, import_util.compHoc)((props) => {
  const cacheHelpInfo = (0, import_react.useRef)({ data: null, p: null });
  const {
    valueField = "dataNo",
    labelField = "title",
    userCodeField = "dataNo",
    title,
    multiple = false,
    selectLeafOnly = false,
    modalProps,
    footer,
    modal = true,
    columns,
    onBeforeOpen,
    typeCode: tc,
    treePid,
    level,
    clientSqlFilter,
    ...others
  } = props;
  const otherProps = others;
  const typeCode = tc || otherProps.helpId;
  delete otherProps.helpId;
  const sqlFilter = (0, import_util.useRefCallback)(async () => {
    if (import_util.iup.isFunction(clientSqlFilter)) {
      return await clientSqlFilter();
    }
    return clientSqlFilter;
  });
  otherProps.onBeforeOpen = (0, import_util.useRefCallback)(async () => {
    const [status, helpInfo] = await (0, import_common.getHelpBeforeOpen)({ onBeforeOpen, cacheHelpInfo });
    if (import_util.iup.isObject(helpInfo)) {
      return helpInfo;
    }
    return status;
  });
  otherProps.request = (0, import_util.useRefCallback)(async ({ keyword }) => {
    var _a;
    const params = await sqlFilter();
    const data = {
      typeCode,
      treePid,
      level,
      filter: ((_a = keyword == null ? void 0 : keyword.trim) == null ? void 0 : _a.call(keyword)) || "",
      ...params
    };
    keyword && (data.filter = keyword);
    const res = await import_util.iup.request.get({
      url: "engine/simpleData/data/treeExt",
      data
    });
    if ((res == null ? void 0 : res.code) === 0)
      return selectLeafOnly ? addDisabledProperty(res.data) : res == null ? void 0 : res.data;
    return [];
  });
  otherProps.valueField = valueField;
  otherProps.userCodeField = userCodeField;
  otherProps.labelField = labelField;
  otherProps.contentParams = {
    footer,
    typeCode,
    multiple,
    selectLeafOnly,
    valueField,
    labelField: otherProps.labelField,
    columns: columns ?? [
      { dataIndex: "dataNo", title: "编码" },
      { dataIndex: "title", title: "名称" }
    ]
  };
  if (title) {
    otherProps.contentParams.helpTitle = title;
  }
  otherProps.selectedRequest = (0, import_util.useRefCallback)(async ({ codes }) => {
    try {
      const { code, data } = await import_util.iup.request.body({
        url: "/engine/simpleData/data/getSimpleDataByTypeAndCodeList",
        skipError: true,
        data: { codeList: codes.split(","), typeCode }
      });
      return code === 0 ? data : [];
    } catch (e) {
    }
    return [];
  });
  if (onBeforeOpen) {
    otherProps.cache = false;
  }
  const { width, height } = (0, import_util.getGlobalConfig)().default.helpConfig;
  return /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp,
    {
      ...otherProps,
      modal,
      isTree: true,
      helpContent: HelpContent,
      multiple,
      modalProps: { width, height, ...modalProps }
    }
  );
}, "StaticDicHelp");
var StaticDicHelpSelect = import_react.default.forwardRef(
  (props, ref) => {
    return /* @__PURE__ */ import_react.default.createElement(StaticDicHelp, { ...props, ref, loadByFocus: true, modal: false, multiple: false });
  }
);
var MultipleStaticDicHelpSelect = import_react.default.forwardRef((props, ref) => {
  return /* @__PURE__ */ import_react.default.createElement(StaticDicHelp, { ...props, ref, loadByFocus: true, modal: false, multiple: true });
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  MultipleStaticDicHelpSelect,
  StaticDicHelp,
  StaticDicHelpSelect
});
